package com.rongchuang.controller;

import com.rongchuang.dto.AssociationDTO;
import com.rongchuang.service.AssociationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("association")
public class AssociationController {

    @Autowired
    private AssociationService associationService;

    /**
     * 分页查询商会信息
     */
    @GetMapping("page")
    public Page<AssociationDTO> pageSearch(@RequestParam(defaultValue = "0") int pageNum,
                                           @RequestParam(defaultValue = "10") int pageSize,
                                           String name) {
        return associationService.pageSearch(pageNum, pageSize, name);
    }

    /**
     * 保存商会信息
     * @param associationDTO 参数
     */
    @PostMapping("modify")
    public void modify(@RequestBody AssociationDTO associationDTO) {
        associationService.modify(associationDTO);
    }

    /**
     * 获取商会信息
     * @param id 商会id
     * @return 商会信息
     */
    @GetMapping("detail/{id}")
    public AssociationDTO detail(@PathVariable Long id) {
        return associationService.getDetail(id);
    }
}
